﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.PresentationFramework.ApplicationModel;
using Caliburn.Core;
using Microsoft.Practices.ServiceLocation;

namespace StockTraderRI.Infrastructure
{
	/// <summary>
	/// Custom implementation of IViewStrategy for the whole projects.
	/// It follows the convention used in StockTraderRI: the view corresponding
	/// to a particular presenter resides in the same namespace of the presenter
	/// (all classes related to a feature falls into a namespace leaf).
	/// Exception will be handled decorating model with ViewAttribute
	/// </summary>
	public class StockTraderViewStrategy : DefaultViewStrategy
	{
		public StockTraderViewStrategy(IAssemblySource assemblySource, IServiceLocator serviceLocator)
			: base(assemblySource, serviceLocator) { }


		protected override string MakeNamespacePart(string part)
		{
			return part;
		}


		protected override IEnumerable<string> ReplaceWithView(Type modelType, string toReplace)
		{
			// MyNamespace.SomethingPresentationModel -> MyNamespace.SomethingView
			// or MyNamespace.SomethingPresenter -> MyNamespace.SomethingView
			if (!string.IsNullOrEmpty(toReplace))
				yield return modelType.Namespace + "." + modelType.Name.Replace(toReplace, "View");

		}
	}
}
